/**
 * @author temsa
 * Tells the Slide Manager when to change Slides
 *
 * @class Slidy.components.slideChangeHandler
 * @name Slidy.components.slideChangeHandler
 * @extends Archetype.component.abstractComponent
 */
$C.create(
/** @scope Slidy.components.slideChangeHandler.prototype */
{
    name: "Slidy.components.slideChangeHandler",
    setup: {
        dependencies: {
            components: {},
            lib: []
        }
    },
    /**
     * Start the Component itself
     * @param {String} altCssClass : alternative css class for click receiver
     */
    initialize: function(){
    	this.firstSlideClickReceiverCssRule= ".firstSlideButton";
    	this.prevSlideClickReceiverCssRule= ".prevSlideButton";
    	this.nextSlideClickReceiverCssRule= ".nextSlideButton";
    	this.lastSlideClickReceiverCssRule= ".lastSlideButton";

    	$$(this.firstSlideClickReceiverCssRule).each(this.firstSlideClickHandlerSetter);
    	$$(this.prevSlideClickReceiverCssRule).each(this.prevSlideClickHandlerSetter);
        $$(this.nextSlideClickReceiverCssRule).each(this.nextSlideClickHandlerSetter);
        $$(this.lastSlideClickReceiverCssRule).each(this.lastSlideClickHandlerSetter);

        document.onkeypress = this.keyUpHandler;
    },
	/**
	 * Handle keyUp Event on the document
	 * @param {Object} evt
	 * @private
	 */
    _keyUpHandler: function(evt){
        evt = evt || window.event;
        Logger.debug("keyUpHandler received event :", evt);
        var code = evt.keyCode || evt.charCode;

        if (code == Event.KEY_LEFT || code == Event.KEY_BACKSPACE) {
            this.firePreviousSlide();
            Event.stop(evt);
        } else if (code == Event.KEY_RIGHT || code == 32 || code == Event.KEY_RETURN) {
            this.fireNextSlide();
            Event.stop(evt);
        }
    },
	/**
	 * Set the clickHandler for an element
	 * @param {Object} elt
	 */
    firstSlideClickHandlerSetter: function(elt){
        $(elt).observe("click", this.fireFirstSlide);
        Logger.debug(" Added an observer on :", elt);
    },

	/**
	 * Set the clickHandler for an element
	 * @param {Object} elt
	 */
    prevSlideClickHandlerSetter: function(elt){
        $(elt).observe("click", this.firePreviousSlide);
        Logger.debug(" Added an observer on :", elt);
    },
	/**
	 * Set the clickHandler for an element
	 * @param {Object} elt
	 */
    nextSlideClickHandlerSetter: function(elt){
        $(elt).observe("click", this.fireNextSlide);
        Logger.debug(" Added an observer on :", elt);
    },
	/**
	 * Set the clickHandler for an element
	 * @param {Object} elt
	 */
    lastSlideClickHandlerSetter: function(elt){
        $(elt).observe("click", this.fireLastSlide);
        Logger.debug(" Added an observer on :", elt);
    },
//-- events --//
    /**
     * Sends a FirstSlide event
     * @function
     * @event FirstSlide
     */
    fireFirstSlide: _,
    /**
     * Sends a PreviousSlide event
     * @function
     * @event PreviousSlide
     */
    firePreviousSlide: _,
    /**
     * Sends a NextSlide event
     * @function
     * @event NextSlide
     */
    fireNextSlide: _,
    /**
     * Sends a LastSlide event
     * @function
     * @event LastSlide
     */
    fireLastSlide: _,
    /**
     * Sends a GoToSlide event
     * @function
     * @event GoToSlide
     * @param {Number} number the slide number you want to go
     */
    fireGoToSlide: _
});
